package com.google.android.material.chip;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewGroup.OnHierarchyChangeListener;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import androidx.annotation.BoolRes;
import androidx.annotation.DimenRes;
import androidx.annotation.Dimension;
import androidx.annotation.IdRes;
import androidx.annotation.Nullable;
import com.google.android.material.internal.FlowLayout;
import o.aqu.d;
import o.aqu.f;
import o.aqu.n;
import o.asa;

public class ChipGroup extends FlowLayout {
    private e ʽ;
    @Nullable
    private c ˊ;
    @Dimension
    private int ˋ;
    private final b ˎ;
    @Dimension
    private int ˏ;
    private boolean ॱ;
    @IdRes
    private int ॱॱ;
    private boolean ᐝ;

    public static class LayoutParams extends MarginLayoutParams {
        public LayoutParams(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
        }

        public LayoutParams(android.view.ViewGroup.LayoutParams layoutParams) {
            super(layoutParams);
        }

        public LayoutParams(int i, int i2) {
            super(i, i2);
        }
    }

    class b implements OnCheckedChangeListener {
        final /* synthetic */ ChipGroup ˊ;

        private b(ChipGroup chipGroup) {
            this.ˊ = chipGroup;
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            if (!this.ˊ.ᐝ) {
                int id = compoundButton.getId();
                if (z) {
                    if (!(this.ˊ.ॱॱ == -1 || this.ˊ.ॱॱ == id || !this.ˊ.ॱ)) {
                        this.ˊ.ˏ(this.ˊ.ॱॱ, false);
                    }
                    this.ˊ.ॱ(id);
                } else if (this.ˊ.ॱॱ == id) {
                    this.ˊ.ॱ(-1);
                }
            }
        }
    }

    public interface c {
        void ˎ(ChipGroup chipGroup, @IdRes int i);
    }

    class e implements OnHierarchyChangeListener {
        final /* synthetic */ ChipGroup ˊ;
        private OnHierarchyChangeListener ॱ;

        private e(ChipGroup chipGroup) {
            this.ˊ = chipGroup;
        }

        public void onChildViewAdded(View view, View view2) {
            if (view == this.ˊ && (view2 instanceof Chip)) {
                if (view2.getId() == -1) {
                    int generateViewId;
                    if (VERSION.SDK_INT >= 17) {
                        generateViewId = View.generateViewId();
                    } else {
                        generateViewId = view2.hashCode();
                    }
                    view2.setId(generateViewId);
                }
                ((Chip) view2).ˋ(this.ˊ.ˎ);
            }
            if (this.ॱ != null) {
                this.ॱ.onChildViewAdded(view, view2);
            }
        }

        public void onChildViewRemoved(View view, View view2) {
            if (view == this.ˊ && (view2 instanceof Chip)) {
                ((Chip) view2).ˋ(null);
            }
            if (this.ॱ != null) {
                this.ॱ.onChildViewRemoved(view, view2);
            }
        }
    }

    public ChipGroup(Context context) {
        this(context, null);
    }

    public ChipGroup(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, d.ˊ);
    }

    public ChipGroup(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˎ = new b();
        this.ʽ = new e();
        this.ॱॱ = -1;
        this.ᐝ = false;
        TypedArray ॱ = asa.ॱ(context, attributeSet, n.ˑॱ, i, f.ᐝॱ, new int[0]);
        int dimensionPixelOffset = ॱ.getDimensionPixelOffset(n.ͺˏ, 0);
        setChipSpacingHorizontal(ॱ.getDimensionPixelOffset(n.ˎͺ, dimensionPixelOffset));
        setChipSpacingVertical(ॱ.getDimensionPixelOffset(n.ٴ, dimensionPixelOffset));
        setSingleLine(ॱ.getBoolean(n.ՙ, false));
        setSingleSelection(ॱ.getBoolean(n.י, false));
        dimensionPixelOffset = ॱ.getResourceId(n.ـॱ, -1);
        if (dimensionPixelOffset != -1) {
            this.ॱॱ = dimensionPixelOffset;
        }
        ॱ.recycle();
        super.setOnHierarchyChangeListener(this.ʽ);
    }

    public android.view.ViewGroup.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
        return new LayoutParams(getContext(), attributeSet);
    }

    protected android.view.ViewGroup.LayoutParams generateLayoutParams(android.view.ViewGroup.LayoutParams layoutParams) {
        return new LayoutParams(layoutParams);
    }

    protected android.view.ViewGroup.LayoutParams generateDefaultLayoutParams() {
        return new LayoutParams(-2, -2);
    }

    protected boolean checkLayoutParams(android.view.ViewGroup.LayoutParams layoutParams) {
        return super.checkLayoutParams(layoutParams) && (layoutParams instanceof LayoutParams);
    }

    public void setOnHierarchyChangeListener(OnHierarchyChangeListener onHierarchyChangeListener) {
        this.ʽ.ॱ = onHierarchyChangeListener;
    }

    protected void onFinishInflate() {
        super.onFinishInflate();
        if (this.ॱॱ != -1) {
            ˏ(this.ॱॱ, true);
            ॱ(this.ॱॱ);
        }
    }

    public void addView(View view, int i, android.view.ViewGroup.LayoutParams layoutParams) {
        if (view instanceof Chip) {
            Chip chip = (Chip) view;
            if (chip.isChecked()) {
                if (this.ॱॱ != -1 && this.ॱ) {
                    ˏ(this.ॱॱ, false);
                }
                ॱ(chip.getId());
            }
        }
        super.addView(view, i, layoutParams);
    }

    @Deprecated
    public void setDividerDrawableHorizontal(Drawable drawable) {
        throw new UnsupportedOperationException("Changing divider drawables have no effect. ChipGroup do not use divider drawables as spacing.");
    }

    @Deprecated
    public void setDividerDrawableVertical(@Nullable Drawable drawable) {
        throw new UnsupportedOperationException("Changing divider drawables have no effect. ChipGroup do not use divider drawables as spacing.");
    }

    @Deprecated
    public void setShowDividerHorizontal(int i) {
        throw new UnsupportedOperationException("Changing divider modes has no effect. ChipGroup do not use divider drawables as spacing.");
    }

    @Deprecated
    public void setShowDividerVertical(int i) {
        throw new UnsupportedOperationException("Changing divider modes has no effect. ChipGroup do not use divider drawables as spacing.");
    }

    @Deprecated
    public void setFlexWrap(int i) {
        throw new UnsupportedOperationException("Changing flex wrap not allowed. ChipGroup exposes a singleLine attribute instead.");
    }

    public void ˎ() {
        this.ᐝ = true;
        for (int i = 0; i < getChildCount(); i++) {
            View childAt = getChildAt(i);
            if (childAt instanceof Chip) {
                ((Chip) childAt).setChecked(false);
            }
        }
        this.ᐝ = false;
        ॱ(-1);
    }

    public void setOnCheckedChangeListener(c cVar) {
        this.ˊ = cVar;
    }

    private void ॱ(int i) {
        this.ॱॱ = i;
        if (this.ˊ != null && this.ॱ) {
            this.ˊ.ˎ(this, i);
        }
    }

    private void ˏ(@IdRes int i, boolean z) {
        View findViewById = findViewById(i);
        if (findViewById instanceof Chip) {
            this.ᐝ = true;
            ((Chip) findViewById).setChecked(z);
            this.ᐝ = false;
        }
    }

    public void setChipSpacing(@Dimension int i) {
        setChipSpacingHorizontal(i);
        setChipSpacingVertical(i);
    }

    public void setChipSpacingResource(@DimenRes int i) {
        setChipSpacing(getResources().getDimensionPixelOffset(i));
    }

    public void setChipSpacingHorizontal(@Dimension int i) {
        if (this.ˏ != i) {
            this.ˏ = i;
            ˊ(i);
            requestLayout();
        }
    }

    public void setChipSpacingHorizontalResource(@DimenRes int i) {
        setChipSpacingHorizontal(getResources().getDimensionPixelOffset(i));
    }

    public void setChipSpacingVertical(@Dimension int i) {
        if (this.ˋ != i) {
            this.ˋ = i;
            ˏ(i);
            requestLayout();
        }
    }

    public void setChipSpacingVerticalResource(@DimenRes int i) {
        setChipSpacingVertical(getResources().getDimensionPixelOffset(i));
    }

    public void setSingleLine(@BoolRes int i) {
        setSingleLine(getResources().getBoolean(i));
    }

    public void setSingleSelection(boolean z) {
        if (this.ॱ != z) {
            this.ॱ = z;
            ˎ();
        }
    }

    public void setSingleSelection(@BoolRes int i) {
        setSingleSelection(getResources().getBoolean(i));
    }
}
